package com.ruoyi.fantasy.service.impl;

import java.util.List;

import com.huanzhidadi.fantasy.bean.domain.FantasyTitle;
import com.huanzhidadi.fantasy.bean.domain.FantasyTitlePropertyRequirement;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fantasy.mapper.FantasyTitleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fantasy.mapper.FantasyTitleAbilityMapper;
import com.huanzhidadi.fantasy.bean.domain.FantasyTitleAbility;
import com.ruoyi.fantasy.service.IFantasyTitleAbilityService;
import com.ruoyi.common.core.text.Convert;

/**
 * 称号能力Service业务层处理
 * 
 * @author wanghui
 * @date 2020-04-11
 */
@Service
public class FantasyTitleAbilityServiceImpl implements IFantasyTitleAbilityService 
{
    @Autowired
    private FantasyTitleAbilityMapper fantasyTitleAbilityMapper;

    @Autowired
    private FantasyTitleMapper fantasyTitleMapper;

    /**
     * 查询称号能力
     * 
     * @param id 称号能力ID
     * @return 称号能力
     */
    @Override
    public FantasyTitleAbility selectFantasyTitleAbilityById(String id)
    {
        return fantasyTitleAbilityMapper.selectFantasyTitleAbilityById(id);
    }

    /**
     * 查询称号能力列表
     * 
     * @param fantasyTitleAbility 称号能力
     * @return 称号能力
     */
    @Override
    public List<FantasyTitleAbility> selectFantasyTitleAbilityList(FantasyTitleAbility fantasyTitleAbility)
    {
        return fantasyTitleAbilityMapper.selectFantasyTitleAbilityList(fantasyTitleAbility);
    }

    /**
     * 新增称号能力
     * 
     * @param fantasyTitleAbility 称号能力
     * @return 结果
     */
    @Override
    public int insertFantasyTitleAbility(FantasyTitleAbility fantasyTitleAbility)
    {
        fantasyTitleAbility.setCreateTime(DateUtils.getNowDate());
        return fantasyTitleAbilityMapper.insertFantasyTitleAbility(fantasyTitleAbility);
    }

    /**
     * 修改称号能力
     * 
     * @param fantasyTitleAbility 称号能力
     * @return 结果
     */
    @Override
    public int updateFantasyTitleAbility(FantasyTitleAbility fantasyTitleAbility)
    {
        fantasyTitleAbility.setUpdateTime(DateUtils.getNowDate());
        return fantasyTitleAbilityMapper.updateFantasyTitleAbility(fantasyTitleAbility);
    }

    /**
     * 删除称号能力对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteFantasyTitleAbilityByIds(String ids)
    {
        return fantasyTitleAbilityMapper.deleteFantasyTitleAbilityByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除称号能力信息
     * 
     * @param id 称号能力ID
     * @return 结果
     */
    @Override
    public int deleteFantasyTitleAbilityById(String id)
    {
        return fantasyTitleAbilityMapper.deleteFantasyTitleAbilityById(id);
    }

    @Override
    public void transforData(List<FantasyTitleAbility> list) {

        for (FantasyTitleAbility titleAbility : list) {
            FantasyTitle fantasyTitle = fantasyTitleMapper.selectFantasyTitleById(titleAbility.getTitleId());
            if (fantasyTitle != null) {
                titleAbility.setTitleId(fantasyTitle.getTitle());
            }
        }
    }
}
